package com.itheima.principles.LiskovSubstitution.before;

/*
 *@ProjectName:design_patterns
 *@Description:
 *@Time: 2021/10/11 8:38
 *@Author: XGQ
 */
public class Client {
    
    public static void main(String[] args) {
        //创建长方形对象
        Rectangle rec = new Rectangle();
        //设置长和宽
        rec.setLength(20);
        rec.setWidth(10);
        //调用resize方法进行扩宽
        resize(rec);
        printLengthAndWidth(rec);
    
        System.out.println("==================");
        
        //创建正方形对象
        Square squ = new Square();
        //设置长和宽
        squ.setLength(10);
        //调用resize方法进行扩宽
        resize(squ);
        printLengthAndWidth(squ);
    }
    
    //扩宽方法
    public static void resize(Rectangle rectangle) {
        //判断宽如果比长小，进行扩宽的操作
        while(rectangle.getWidth() <= rectangle.getLength()) {
            rectangle.setWidth(rectangle.getWidth() + 1);
        }
    }
    
    //打印长和宽
    public static void printLengthAndWidth(Rectangle rectangle) {
        System.out.println(rectangle.getLength());
        System.out.println(rectangle.getWidth());
    }
}
